var express = require('express');
var router = express.Router();
var novelModel = require('../Models/NovelsNodel.js');
var shortModel = require('../Models/ShortModel.js')
// 获取所有小说
router.get('/jingxuan',function(req,res,next){
	novelModel.find().then((novels)=>{
		if(novels.length==0){
			res.send({
			  code: 0,
			  msg: '未搜索到结果',
			})
		}else{
			res.send({
			  code: 1,
			  msg: '所有小说',
			  data:novels
			})
		}
	});

})


//获取所有短篇小说
router.get('/short',function(req,res,next){
	shortModel.find().then((novels)=>{
		if(novels.length==0){
			res.send({
			  code: 0,
			  msg: '未搜索到结果',
			})
		}else{
			res.send({
			  code: 1,
			  msg: '所有小说',
			  data:novels
			})
		}
	});
	
})

//查找小说
router.get('/novel',function(req,res,next){
	let name = req.query.name
	console.log(name)
	novelModel.find({"name":[name]}).then((val)=>{
		console.log(val);
		if(val.length==0){
			res.send({
				code:0,
				msg:"查找失败",
			})
		}else{
			res.send({
				code:1,
				msg:"查找成功",
				data:val
			})
		}
	})
})
module.exports = router;